package com.sc.nft.task;

import com.sc.nft.service.MallUserPropsReleasedDetailService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * 用户道具释放
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class MallUserPropsReleasedTask {

    private final MallUserPropsReleasedDetailService mallUserPropsReleasedDetailService;

    /**
     * 商城活动道具释放
     *
     * @throws Exception
     */
    @XxlJob("mallUserPropsReleased")
    public void mallUserPropsReleased() throws Exception {
        // 方式1：从任务参数中获取日期字符串
        String dateStr = XxlJobHelper.getJobParam();
        Date date;
        Boolean isSpecifyDate = false;
        if (StringUtils.isNotBlank(dateStr)) {
            // 将字符串转换为Date对象，假设格式为yyyy-MM-dd
            date = DateUtils.parseDate(dateStr, "yyyy-MM-dd");
            isSpecifyDate = true;
        } else {
            date = new Date();
        }
        mallUserPropsReleasedDetailService.propsReleasedTask(date, isSpecifyDate);
    }

}
